﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace hozoroghiab
{
    public partial class naghesia : Form
    {
        public sql sqlquery;
        public naghesia(sql s)
        {
            InitializeComponent();
            sqlquery = s;
        }

        private void naghesia_Load(object sender, EventArgs e)
        {


        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Dictionary<int, int> naghes = new Dictionary<int, int>();
            
            if (yeartoolStripTextBox1.Text != "" && yeartoolStripTextBox1.Text.Length==4)
            {
                sqlquery.open();
                SqlDataReader data = sqlquery.ExecuteQuery("SELECT employeid,count(employeid) FROM entry WHERE month=" + monthtoolStripComboBox1.Text.Trim() + " and year=" + yeartoolStripTextBox1.Text.Trim() + " GROUP BY employeid");
                if (data.HasRows)
                {
                    string where = "";
                    while (data.Read())
                    {
                        if ((int)data[1] % 2 != 0)
                        {
                            where += "employeid=" + (int)data[0] + " or ";
                        }
                    }
                    sqlquery.close();
                    if (where.Length > 4)
                    {
                        sqlquery.open();
                        SqlDataAdapter data2 = sqlquery.sqlcommand("SELECT rtrim(name)+' '+rtrim(family) as [نام و نام خانوادگی],unit as [واحد] FROM profile WHERE " + where.Substring(0, where.Length - 4));
                        DataTable dt = new DataTable();
                        data2.Fill(dt);
                        dataGridView1.DataSource = dt;
                        sqlquery.close();
                    }
                }
                
            }
        }


    }
}
